﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Ink;

namespace LessonStudio.Models
{
    /// <summary>
    /// 某一页[Page]的相关画笔数据
    /// 默认有一个画笔数据
    /// 点击清除画笔的时候，添加一个画笔数据
    /// </summary>
    public class LessonViewItem
    {
        public string FilePath { get; set; }
        public int Page { get; set; }
        public int Index { get; set; }
        public List<StrokeCollection> Strokes { get; private set; }

        /// <summary>
        /// 下一个画笔
        /// </summary>
        /// <returns></returns>
        public StrokeCollection Next()
        {
            if (Index < 0) return null;

            if(Index < Strokes.Count - 1)
            {
                Index++;
                return Strokes[Index];
            }

            return null;
        }

        /// <summary>
        /// 上一个画笔
        /// </summary>
        /// <returns></returns>
        public StrokeCollection Prev()
        {
            if (Index >= Strokes.Count) return null;

            if (Index > 0)
            {
                Index--;
                return Strokes[Index];
            }

            return null;
        }

        /// <summary>
        /// 第一个画笔
        /// </summary>
        /// <returns></returns>
        public StrokeCollection First()
        {
            if (Strokes == null || Strokes.Count == 0) return null;

            Index = 0;
            return Strokes[Index];
        }

        /// <summary>
        /// 最后一个画笔
        /// </summary>
        /// <returns></returns>
        public StrokeCollection Last()
        {
            if (Strokes == null || Strokes.Count == 0) return null;

            Index = Strokes.Count - 1;
            return Strokes[Index];
        }

        /// <summary>
        /// 当前画笔
        /// </summary>
        /// <returns></returns>
        public StrokeCollection Current()
        {
            if (Index >= Strokes.Count) return null;

            if (Index >= 0)
            {
                return Strokes[Index];
            }

            return null;
        }

        public void Add()
        {
            this.Index = this.Strokes.Count;
            this.Strokes.Add(new StrokeCollection());
        }

        public LessonViewItem()
        {
            this.Strokes = new List<StrokeCollection>();
            this.Strokes.Add(new StrokeCollection());
            this.Index = 0;
        }
    }
}
